package com.endpoint.search.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Project: endpoint
 * @Name: RedissonConfig
 * @Author: Jack_Li
 * @Date: 2024/7/4 18:40
 */

@Configuration
public class RedissonConfig {

    @Value("${spring.redis.host}")
    private String host;

    @Value("${spring.redis.port}")
    private String port;

    @Value("${spring.redis.password}")
    private String password;

    @Bean(destroyMethod = "shutdown")
    public RedissonClient redissonClient() {
        //1、创建配置
        Config config = new Config();
        //2.使用单节点实例 注意:地址要带上redis:// 或者安全实例 rediss://
        config.useSingleServer().setAddress("redis://" +  host + ":" + port);
        config.useSingleServer().setPassword(password);
        //根据Config创建出RedisClient实例
        RedissonClient redisson = Redisson.create(config);
        return redisson;
    }

}
